package io.renren.modules.file.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.file.dao.OperLogDao;
import io.renren.modules.file.entity.OperLogEntity;
import io.renren.modules.file.service.OperLogService;


@Service("operLogService")
public class OperLogServiceImpl extends ServiceImpl<OperLogDao, OperLogEntity> implements OperLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //开始结束时间
        String startTime = (String)params.get("startTime");
        String endTime = (String)params.get("endTime");
        String fileName = ((String)params.get("fileName"));
        if (StringUtils.isNotBlank(fileName)) {
            fileName = fileName.trim();
        }
        IPage<OperLogEntity> page = this.page(
                new Query<OperLogEntity>().getPage(params),
                new QueryWrapper<OperLogEntity>().like(StringUtils.isNotBlank(fileName),"file_name", fileName).or()
                        .like(StringUtils.isNotBlank(fileName),"oper_user_name", fileName).or()
                        .like(StringUtils.isNotBlank(fileName),"type", fileName)
                        .between(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime),"creat_time",startTime,endTime)
        );

        return new PageUtils(page);
    }

}
